package com.jgp.sys.ui;

import com.jgp.sys.ui.functions.DataSourceFunction;
import com.jgp.sys.ui.functions.TransformValue;
import com.jgp.sys.ui.model.Grid;

import java.util.List;

/**
 * 项目   sys
 * 作者   loufei
 * 时间   2018/3/11
 */
public class GridResult {
    private Grid grid;
    private Pager pager;
    private List<Category> cats;
    private List<Object> selectedKeys;
    private List<FormResult> records;
    
    public Grid getGrid() {
        return grid;
    }
    
    public void setGrid(Grid grid) {
        this.grid = grid;
    }
    
    public Pager getPager() {
        return pager;
    }
    
    public void setPager(Pager pager) {
        this.pager = pager;
    }
    
    public List<Category> getCats() {
        return cats;
    }
    
    public void setCats(List<Category> cats) {
        this.cats = cats;
    }
    
    public List<FormResult> getRecords() {
        return records;
    }
    
    public void setRecords(List<FormResult> records) {
        this.records = records;
    }
    
    public List<Object> getSelectedKeys() {
        return selectedKeys;
    }
    
    public void setSelectedKeys(List<Object> selectedKeys) {
        this.selectedKeys = selectedKeys;
    }
    
    public static class Category {
        private String title;
        private String name;
        //drop activeKey
        private String activeKey;
        //映射的实体类型
        private Class<?> mapperClass;
        //关联字段
        private String relationName;
        //映射为要显示的字段
        private String mapperName;
        private List<Object> displayValues;
        private DataSourceFunction dataSourceList;
        private TransformValue transformValue;
        
        /**
         * 普通列
         *
         * @param title 标题
         * @param name  映射字段
         */
        public Category(String title, String name) {
            this.title = title;
            this.name = name;
        }
        
        /**
         * 有DROP的列
         *
         * @param title     标题
         * @param name      映射字段
         * @param activeKey 下拉功能组标识
         */
        public Category(String title, String name, String activeKey) {
            this.title = title;
            this.name = name;
            this.activeKey = activeKey;
        }
        
        /**
         * 外键列 通过id关联
         *
         * @param title       标题
         * @param name        映射字段
         * @param mapperClass 对应实体的 repository class 或 对应实体的 class
         * @param mapperName  被映射实体所需要显示的字段
         */
        public Category(String title, String name, Class<?> mapperClass, String mapperName) {
            this.title = title;
            this.name = name;
            this.mapperClass = mapperClass;
            this.mapperName = mapperName;
        }
        
        
        /**
         * 非外键关联，而是通过关联实体的其他字段，
         *
         * @param title        标题
         * @param name         映射字段
         * @param mapperClass  对应实体的 repository class 或 对应实体的 class
         * @param relationName 主表实体中映射字段保存的值为关联实体的某个非id字段，必须保证该字段的值在关联实体所对应的表中是唯一的
         * @param mapperName   被映射实体所需要显示的字段
         */
        public Category(String title, String name, Class<?> mapperClass, String relationName, String
                mapperName) {
            this.title = title;
            this.name = name;
            this.mapperClass = mapperClass;
            this.relationName = relationName;
            this.mapperName = mapperName;
        }
        
        /**
         * 自定义数据源列表
         *
         * @param title          标题
         * @param name           映射字段
         * @param relationName   主表实体中映射字段保存的值为关联实体的某个非id字段，必须保证该字段的值在关联实体所对应的表中是唯一的
         * @param mapperName     被映射实体所需要显示的字段
         * @param dataSourceList {@link DataSourceFunction} 数据源
         */
        public Category(String title, String name, String relationName, String mapperName, DataSourceFunction
                dataSourceList) {
            this.title = title;
            this.name = name;
            this.dataSourceList = dataSourceList;
            this.relationName = relationName;
            this.mapperName = mapperName;
        }
        
        public String getTitle() {
            return title;
        }
        
        public void setTitle(String title) {
            this.title = title;
        }
        
        public String getName() {
            return name;
        }
        
        public void setName(String name) {
            this.name = name;
        }
        
        public String getActiveKey() {
            return activeKey;
        }
        
        public Category setActiveKey(String activeKey) {
            this.activeKey = activeKey;
            return this;
        }
        
        public Class<?> getMapperClass() {
            return mapperClass;
        }
        
        public void setMapperClass(Class<?> mapperClass) {
            this.mapperClass = mapperClass;
        }
        
        public String getRelationName() {
            return relationName;
        }
        
        public void setRelationName(String relationName) {
            this.relationName = relationName;
        }
        
        public String getMapperName() {
            return mapperName;
        }
        
        public void setMapperName(String mapperName) {
            this.mapperName = mapperName;
        }
        
        public List<Object> getDisplayValues() {
            return displayValues;
        }
        
        public void setDisplayValues(List<Object> displayValues) {
            this.displayValues = displayValues;
        }
        
        public DataSourceFunction getDataSourceList() {
            return dataSourceList;
        }
        
        public void setDataSourceList(DataSourceFunction dataSourceList) {
            this.dataSourceList = dataSourceList;
        }
    }
}
